package com.tzxs.pay.main.activity;

import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import com.tzxs.pay.R;
import com.tzxs.pay.databinding.FragmentActivityBinding;
import com.tzxs.pay.main.BaseFragment;
import com.tzxs.pay.main.mine.MerchantsActivityFragment;
import com.tzxs.pay.main.mine.PlatformActivityFragment;

import java.util.ArrayList;
import java.util.List;

public class ActivityFragment extends BaseFragment<FragmentActivityBinding> {
    private String[] title = {"平台活动", "商家活动"};
    private List<Fragment> list;

    @Override
    public int getContentLayoutId() {
        return R.layout.fragment_activity;
    }

    @Override
    protected void viewCreate(Bundle savedInstanceState) {
        initFragmentList();
        binding.activityTab.setupWithViewPager(binding.activityVp);
        binding.activityVp.setAdapter(new ActivityVpAdapter(getChildFragmentManager()));
    }

    //初始化fragment
    private void initFragmentList() {
        list = new ArrayList<>();
        list.add(new PlatformActivityFragment());
        list.add(new MerchantsActivityFragment());
    }

    class ActivityVpAdapter extends FragmentStatePagerAdapter {

        private ActivityVpAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {

            return list.get(position);
        }

        @Override
        public int getCount() {
            return title.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return title[position];
        }
    }
}
